package com.dq.domain.record;

import com.dq.vo.baseVo.VO;
import com.dq.domain.base.BaseEntity;

import com.dq.domain.org.Org;
import com.dq.domain.sys.user.user.StaffUser;
import com.dq.domain.sys.user.user.base.SysUser;
import com.dq.domain.sys.user.user.WxUser;
import com.dq.utils.TimeUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;

/**
 * @author liuhui
 * @date 2019/11/20 0020 15:47:10
 */
@Data
@Entity
@ApiModel("维护记录")
public class MaintainRecord extends BaseEntity implements VO.ToVO {

    @ApiModelProperty("跟踪编号")
    protected String trackNo;

    @ApiModelProperty("跟踪用户")
    @ManyToOne
    protected SysUser wxUser;

    @ApiModelProperty("记录所属门店")
    @ManyToOne
    protected Org sysDept;

    @ApiModelProperty("维护技师")
    @ManyToOne
    protected SysUser staffUser;

    @ApiModelProperty("跟踪内容")
    protected String maintainContent;

    @ApiModelProperty("跟踪状态")
    protected MaintainStatus maintainStatus;

    @ApiModelProperty("跟踪方式")
    protected MaintainType maintainType;

    @ApiModelProperty("跟踪开始时间")
    protected Long beginTime;
    @ApiModelProperty("维护时间")
    protected Long maintainTime;

    @ApiModelProperty("跟踪结束时间")
    protected Long endTime;

    @ApiModelProperty("服务时间")
    protected Long serviceTime;
    @ApiModelProperty("凭证")
    @Column(name="voucher", columnDefinition="text")
    protected String voucher;
    @ApiModelProperty("跟踪超时时间")
    protected Long timeoutTime;

    public enum MaintainStatus{
        noVisit("未回访"),visited("已回访"),expire("超时");

        public String name;

        MaintainStatus(String name){
            this.name = name;
        }
    }

    public enum MaintainType{
        wx("微信"),phone("电话");

        public String name;

        MaintainType(String name){
            this.name = name;
        }
    }

    @Data
    @ApiModel(value = "跟踪记录视图")
    public static class Vo implements VO {

    }

    @Data
    @ApiModel("门店用户跟踪记录列表视图")
    public static class OrgTrackListVo{
        @ApiModelProperty("id")
        protected Long id;
        @ApiModelProperty("跟踪编号")
        protected String trackNo;
        @ApiModelProperty("开始时间")
        protected String beginTime;
        @ApiModelProperty("结束时间")
        protected String endTime;
        @ApiModelProperty("技师真实姓名")
        protected String staffRealCName;
        @ApiModelProperty("跟踪类型")
        protected String trackType;
        @ApiModelProperty("跟踪内容")
        protected String trackContent;


    }

    public OrgTrackListVo toOrgTrackListVo(){
        MaintainRecord.OrgTrackListVo orgTrackListVo = new MaintainRecord.OrgTrackListVo();
        orgTrackListVo.id = this.getId();
        orgTrackListVo.trackNo = fmt(this.getTrackNo());
        orgTrackListVo.beginTime= fmt(this.getBeginTime(), TimeUtil.YYYY_MM_DD_HH_MM_SS);
        orgTrackListVo.endTime = fmt(this.getEndTime(),TimeUtil.YYYY_MM_DD_HH_MM_SS);
        StaffUser staffUser = (StaffUser)this.getStaffUser();
        orgTrackListVo.staffRealCName = fmt(staffUser.getUserRealcName());
        orgTrackListVo.trackType = fmt(this.getMaintainType().name);
        orgTrackListVo.trackContent = fmt(this.getMaintainContent());
        return orgTrackListVo;
    }

    @Override
    public VO toVO(boolean isRecursion) {
        Vo vo = new Vo();

        return vo;
    }

    @Data
    @ApiModel("技师跟踪记录列表视图")
    public static class StaffTrackListVo{
        @ApiModelProperty("id")
        protected Long id;
        @ApiModelProperty("维护编号")
        protected String trackNo;

        @ApiModelProperty("维护时间")
        protected String maintainTime;
        @ApiModelProperty("服务时间")
        protected String serviceTime;
        @ApiModelProperty("维护状态")
        protected String maintainStatus;
        @ApiModelProperty("维护状态")
        protected MaintainStatus maintainStatusEN;
        @ApiModelProperty("跟踪内容")
        protected String maintainContent;
        @ApiModelProperty("凭证")
        protected String voucher;

        @ApiModelProperty("维护方式")
        protected MaintainType maintainTypeEN;
        @ApiModelProperty("维护方式中文")
        protected String maintainTypeCN;

        @ApiModelProperty("顾客ID")
        protected Long wxUserId;
        @ApiModelProperty("顾客编号")
        protected String wxUserCardNo;
        @ApiModelProperty("顾客姓名")
        protected String name;
        @ApiModelProperty("顾客等级")
        protected String grade;
        @ApiModelProperty("顾客手机号")
        protected String mobile;
        @ApiModelProperty("技师姓名")
        protected String staffUserName;

        @ApiModelProperty("门店名")
        protected String orgName;
    }

    public StaffTrackListVo toStaffTrackListVo(){
        StaffTrackListVo vo = new StaffTrackListVo();
        vo.id = this.id;
        WxUser wxUser = (WxUser) this.wxUser;
        vo.name = wxUser.getUserRealcName();
        vo.wxUserId = wxUser.getId();
        vo.wxUserCardNo = wxUser.getCardNo();
        vo.grade = wxUser.getOrgCustomerLevel()!=null ? wxUser.getOrgCustomerLevel().getLevenName() : "";

        vo.orgName = this.getSysDept().getSimpleName();

        vo.maintainTime = fmt(this.maintainTime,TimeUtil.YYYY_MM_DD_HH_MM_SS);
        vo.serviceTime = fmt(this.serviceTime,TimeUtil.YYYY_MM_DD_HH_MM_SS);
        vo.maintainStatus = this.maintainStatus.name;
        vo.maintainStatusEN = this.maintainStatus;
        vo.maintainContent = this.maintainContent;
        vo.voucher = this.voucher;
        vo.mobile = wxUser.getUsername();
        vo.maintainTypeEN =this.maintainType != null ? this.maintainType:null;
        vo.maintainTypeCN = this.maintainType != null ?this.maintainType.name:"";
        vo.staffUserName = this.staffUser.getUserRealcName();
        vo.trackNo = this.trackNo;
        return vo;
    }
}
